
#include "diskio.h"		/* Declarations of low level disk I/O functions */
#include "sd_spi_mode.h"

/* Card type flags (CardType) */
#define CT_MMC		0x01		/* MMC ver 3 */
#define CT_SD1		0x02		/* SD ver 1 */
#define CT_SD2		0x04		/* SD ver 2 */
#define CT_SDC		(CT_SD1|CT_SD2)	/* SD */
#define CT_BLOCK	0x08		/* Block addressing */

DSTATUS disk_initialize (BYTE drv)
{

    SdDiskInit();//LiLiang
    return RES_OK;
}

DSTATUS disk_status (BYTE drv)
{
  return RES_OK;
}

DWORD get_fattime (void)
{
    return RES_OK;
}


DRESULT disk_read (
	BYTE drv,		/* Physical drive nmuber (0..) */
	BYTE *buff,		/* Data buffer to store read data */
	DWORD sector,	/* Sector address (LBA) */
	UINT count		/* Number of sectors to read (1..255) */  //typedef unsigned char	BYTE;
)
{
    DRESULT result;
    Int32U ccount=count;
    switch (drv)
    {
        case 0 :
        if((SdDiskIO(buff,sector,ccount,DiskRead))==DiskCommandPass) // /* READ_SINGLE_BLOCK */ count==1
                   result=RES_OK;               // Only Single Mode;
                else
                   result=RES_ERROR;  //LiLiang
            break;


        default:
            result=RES_ERROR;
            break;
    }
    return result;

}

DRESULT disk_write (
	BYTE drv,			/* Physical drive nmuber (0..) */
	const BYTE *buff,	/* Data to be written */
	DWORD sector,		/* Sector address (LBA) */
	UINT count			/* Number of sectors to write (1..255) */
)
{
    DRESULT result;
    BYTE *pBuf = (BYTE*)buff;
    Int32U ccount= count;
    switch (drv)
    {
        case 0 :
           if((SdDiskIO(pBuf,sector,ccount,DiskWrite))==DiskCommandPass)//_SdOk) //   DiskCommandPass = 0, DiskNotReady, DiskNotPresent,
                                                                           //DiskParametersError, DiskMiscompareError, DiskChanged,
                                                                           // DiskUknowError,
                   result=RES_OK;
               else
                   result=RES_ERROR;//LiLiang
            break;

        default:
            result=RES_ERROR;
            break;
    }
    return result;
}


DRESULT disk_ioctl (
	BYTE drv,		/* Physical drive nmuber (0..) */
	BYTE ctrl,		/* Control code */
	void *buff		/* Buffer to send/receive control data */
)

{
    DRESULT result;

    switch (drv)
    {
        case 0 :
            result = RES_OK;
            break;
        default:
            result=RES_ERROR;
            break;
    }

    return result;
}




